<?php
/**
 * User: zoudingyong <sheyingtg@qq.com>
 * Date: 2018/11/06
 */

namespace classes;

use think\Db;

class Goods
{

    static public $order_goods = 'jixie_order_goods';
    static public $goods = 'jixie_goods';

    /**
     * 购买商品及其他逻辑处理
     * @param $order
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    static public function Buy($order)
    {
        $goodsInfo = Db::name(self::$order_goods)
            ->where(['order_id' => $order['order_id']])
            ->select();
        foreach ($goodsInfo as $one) {
            //产品销售更新
            $quantity = $one['total_num'];
            DB::name(self::$goods)->where('goods_id', $one['goods_id'])
                ->update(
                    [
                        'sales_actual' => Db::raw('sales_actual+' . $quantity),
                    ]);
        }

    }

}